package com.caregiver.watch.business.care.model.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

import static com.caregiver.watch.common.constant.NumberConstants.ZERO;

/**
 * @description: 周睡眠详情
 * @program: caregiver-watch
 * @author: 疆戟
 * @create: 2025-10-01 23:01
 */
@Data
@Schema(description = "周睡眠详情")
public class WeekSleepDetailVo {

    // 平均睡眠等分
    @Schema(description = "平均睡眠等分")
    private Integer averageSleepScore;

    @Schema(description = "睡眠详情")
    private List<SleepDetailVo> sleepDetail;


    public static WeekSleepDetailVo build(List<SleepDetailVo> sleepDetail) {
        WeekSleepDetailVo weekSleepDetail = new WeekSleepDetailVo();
        if (CollectionUtils.isEmpty(sleepDetail)) {
            weekSleepDetail.setAverageSleepScore(ZERO);
            weekSleepDetail.setSleepDetail(new ArrayList<>());
            return weekSleepDetail;
        }
        // 计算平均睡眠得分
        Integer averageSleepScore = sleepDetail.stream().mapToInt(SleepDetailVo::getSleepScore).sum() / sleepDetail.size();
        weekSleepDetail.setAverageSleepScore(averageSleepScore);
        weekSleepDetail.setSleepDetail(sleepDetail);
        return weekSleepDetail;
    }
}
